package com.abel.demo.service.impl;

import com.abel.demo.service.AsyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

@Slf4j
@Service
public class AsyncServiceImpl implements AsyncService {

    @Async
    @Override
    public void test1(int n) {
        try {
//            Thread.sleep(1500);
            log.info("线程n:{}", n);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Async
    @Override
    public Future<String> test2(int n) {
        try {
            Thread.sleep(1000);
            log.info("线程n:{}", n);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new AsyncResult<String>("n:"+n);
    }
}
